package com.typeinfo.LatentReflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class LatentReflection {
   public static void main(String[] args) {
	  CommunicateReflectively.perform(new Mime());
	  CommunicateReflectively.perform(new SmartDog());
  }
}
class Mime{
	public void walkAginstTheWind(){}
	public void sit(){
		System.out.println("Pretenting to sit");
	}
	public void pushInvisibleWalla(){}
	public String toString(){
		return "Mime";
	}
}
class SmartDog{
	public void speak(){
		System.out.println("woof");
	}
	public void sit(){
		System.out.println("Sitting");
	}
	public void reproduce(){}
}
class CommunicateReflectively{
	public static void perform(Object speaker){
		Class<?> spkr=speaker.getClass();
		try {
			Method speak=spkr.getMethod("speak");
			try {
				speak.invoke(speaker);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			Method sit=spkr.getMethod("sit");
			try {
				sit.invoke(speaker);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}